package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 5:34 PM
 */
object Test04_Access {
  def main(args: Array[String]): Unit = {
    val person = new Person
    //    println(person.idCard)
    //println(person.name)
    println(person.age)
    println(person.sex)
    person.printInfo()

    val worker = new Worker
    worker.printInfo()
  }

}

// 定义一个子类
class Worker extends Person {
  override def printInfo(): Unit = {
    //    println(idCard) // error
    name = "bob"
    age = 25
    sex = "male"
    println(s"Worker: $name $sex $age")
  }
}